package myky.com.doctorapp.adapter

import android.view.ViewTreeObserver
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.facebook.drawee.view.SimpleDraweeView
import myky.com.doctorapp.R
import myky.com.doctorapp.api.Address
import myky.com.doctorapp.entity.MyDoctorEntity
import myky.com.doctorapp.utils.UriUtils

class MyDocotorAdapter(docotors: List<MyDoctorEntity.DataBean>) : BaseQuickAdapter<MyDoctorEntity.DataBean, BaseViewHolder>(R.layout.activity_author__list_item, docotors) {
    override fun convert(helper: BaseViewHolder?, item: MyDoctorEntity.DataBean?) {


        val header = helper?.getView<SimpleDraweeView>(R.id.author_list_item_header)

        val imageView = helper?.getView<ImageView>(R.id.author_list_item_check)

        helper?.setText(R.id.author_list_item_realName, item?.realname)

        header?.setImageURI(UriUtils.getUriInstance().getUri(item?.headPhoto))

        val ll_text = helper?.getView<LinearLayout>(R.id.author_list_item_ll)

        val tv_text = helper?.getView<TextView>((R.id.author_list_item_hospital))

        helper?.setText(R.id.author_list_item_department, item?.departmentname)

        helper?.setText(R.id.author_list_item_hospital, item?.hospitalname)

        helper?.setText(R.id.author_list_item_gootAt, item?.experience)

        val ll_width = IntArray(1)

        val tv_width = IntArray(1)

        ll_text?.viewTreeObserver?.addOnPreDrawListener(ViewTreeObserver.OnPreDrawListener {
            ll_width[0] = ll_text.width
            true
        })
        tv_text?.viewTreeObserver?.addOnPreDrawListener(ViewTreeObserver.OnPreDrawListener {
            tv_width[0] = tv_text.width
            true
        })
        if (tv_width[0] > ll_width[0]) {
            helper?.setText(R.id.author_list_item_hospital, item?.hospitalname + "\u3000\r\n" + item?.departmentname)
        }
        if (item?.casepermission === 0) {
            imageView?.setImageResource(R.drawable.wdys_an_hs)
        } else if (item?.casepermission === 1) {
            imageView?.setImageResource(R.drawable.wdys_an)
        }

        helper?.addOnClickListener(R.id.author_list_item_check)
        helper?.addOnClickListener(R.id.author_list_item_click_lin)
        helper?.addOnClickListener(R.id.author_list_item_header)
    }
}